using System.Linq;
using System.Text;
using BizTalk.BuildGenerator.MetaData;

namespace BizTalk.BuildGenerator.BuildFrameworks.Default.CommandBuilders.BizTalkHost
{   
    public class StartHostCommandBuilder : ICommandBuilder
    {
        private const string Command = "\t\t<BizTalk.BuildGenerator.Tasks.StartHost HostName=\"{0}\" />";
        private const string Key = "<!-- @StartHostCommand@ -->";


        #region ICommandBuilder Members
        /// <summary>
        /// Implements the Command Builder
        /// </summary>
        /// <param name="args"></param>
        /// <param name="fileBuilder"></param>
        public void Build(GenerationArgs args, StringBuilder fileBuilder)
        {
            var sb = new StringBuilder();

            foreach (var cmd in
                args.BizTalkHosts.Hosts.Where(host => host.HostType == BizTalkHostType.InProcess).Select(
                    host => string.Format(Command, host.Name)))
            {
                sb.AppendLine(cmd);
            }

            fileBuilder.Replace(Key, sb.ToString());
        }

        #endregion
    }
}
